﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO;
using System.Data.OleDb;


namespace App1
{
    public partial class frmSave : Form
    {
        public frmSave()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text.ToString() + ".txt";

            FileInfo myfile = new FileInfo(textBox1.Text);
            StreamWriter tex = myfile.CreateText();
            int i = 0;

            while (i < 2)
            {
                // luu vao file 
                tex.WriteLine(i);// player // 1
                // pawns /2-3-4-5-6
                tex.WriteLine(GameChess.Player[i].Pawns[0].SaveRow().ToString() + " " + GameChess.Player[i].Pawns[0].SaveCol().ToString() + " " + GameChess.Player[i].Pawns[0].State.ToString());
                tex.WriteLine(GameChess.Player[i].Pawns[1].SaveRow().ToString() + " " + GameChess.Player[i].Pawns[1].SaveCol().ToString() + " " + GameChess.Player[i].Pawns[1].State.ToString());
                tex.WriteLine(GameChess.Player[i].Pawns[2].SaveRow().ToString() + " " + GameChess.Player[i].Pawns[2].SaveCol().ToString() + " " + GameChess.Player[i].Pawns[2].State.ToString());
                tex.WriteLine(GameChess.Player[i].Pawns[3].SaveRow().ToString() + " " + GameChess.Player[i].Pawns[3].SaveCol().ToString() + " " + GameChess.Player[i].Pawns[3].State.ToString());
                tex.WriteLine(GameChess.Player[i].Pawns[4].SaveRow().ToString() + " " + GameChess.Player[i].Pawns[4].SaveCol().ToString() + " " + GameChess.Player[i].Pawns[4].State.ToString());

                // Guards 7-8
                tex.WriteLine(GameChess.Player[i].Guards[0].SaveRow().ToString() + " " + GameChess.Player[i].Guards[0].SaveCol().ToString() + " " + GameChess.Player[i].Guards[0].State.ToString());
                tex.WriteLine(GameChess.Player[i].Guards[1].SaveRow().ToString() + " " + GameChess.Player[i].Guards[1].SaveCol().ToString() + " " + GameChess.Player[i].Guards[1].State.ToString());

                // Elephants 9-10
                tex.WriteLine(GameChess.Player[i].Elephants[0].SaveRow().ToString() + " " + GameChess.Player[i].Elephants[0].SaveCol().ToString() + " " + GameChess.Player[i].Elephants[0].State.ToString());
                tex.WriteLine(GameChess.Player[i].Elephants[1].SaveRow().ToString() + " " + GameChess.Player[i].Elephants[1].SaveCol().ToString() + " " + GameChess.Player[i].Elephants[1].State.ToString());

                // Horses 11-12
                tex.WriteLine(GameChess.Player[i].Horses[0].SaveRow().ToString() + " " + GameChess.Player[i].Horses[0].SaveCol().ToString() + " " + GameChess.Player[i].Horses[0].State.ToString());
                tex.WriteLine(GameChess.Player[i].Horses[1].SaveRow().ToString() + " " + GameChess.Player[i].Horses[1].SaveCol().ToString() + " " + GameChess.Player[i].Horses[1].State.ToString());

                //Cannons 12-14
                tex.WriteLine(GameChess.Player[i].Cannons[0].SaveRow().ToString() + " " + GameChess.Player[i].Cannons[0].SaveCol().ToString() + " " + GameChess.Player[i].Cannons[0].State.ToString());
                tex.WriteLine(GameChess.Player[i].Cannons[1].SaveRow().ToString() + " " + GameChess.Player[i].Cannons[1].SaveCol().ToString() + " " + GameChess.Player[i].Cannons[1].State.ToString());

                // Rooks 15-16
                tex.WriteLine(GameChess.Player[i].Rooks[0].SaveRow().ToString() + " " + GameChess.Player[i].Rooks[0].SaveCol().ToString() + " " + GameChess.Player[i].Rooks[0].State.ToString());
                tex.WriteLine(GameChess.Player[i].Rooks[1].SaveRow().ToString() + " " + GameChess.Player[i].Rooks[1].SaveCol().ToString() + " " + GameChess.Player[i].Rooks[1].State.ToString());

                // King 17
                tex.WriteLine(GameChess.Player[i].King.SaveRow().ToString() + " " + GameChess.Player[i].King.SaveCol().ToString() + " " + GameChess.Player[i].King.State.ToString());

                i++;
            }
            tex.Close();

            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Save_Load(object sender, EventArgs e)
        {

        }
    }
}
